From Alex Mottram:
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 18 Sep 2002 14:40:54 +0000 (14:40 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 18 Sep 2002 14:40:54 +0000 (14:40 +0000)
1.  add csv_util.c and csv_util.h
2.  change mxf.c to use csv_util / minor other changes
3.  change csv to use csv_util
4.  add OziExplorer 1.1 file format.
5.  remove the extra MXF section from the README

Thanks,

Alex

gpsbabel/Makefile
gpsbabel/README
gpsbabel/csv.c
gpsbabel/mxf.c
gpsbabel/testo
gpsbabel/vecs.c

index 6f324bfd252ac276313a2e156df85a66b2d5c4f1..a81e2e9d6b40816bbd04f465fc1457824873ee76 100644 (file)
@@ -2,15 +2,17 @@ CFLAGS=-g -Icoldsync
 
 FMTS=magproto.o gpx.o geo.o gpsman.o mapsend.o mapsource.o \
        gpsutil.o tiger.o pcx.o csv.o cetus.o gpspilot.o magnav.o \
-       psp.o mxf.o holux.o garmin.o
+       psp.o mxf.o holux.o garmin.o ozi.o
 
 JEEPS=jeeps/gpsapp.o jeeps/gpscom.o jeeps/gpsfmt.o jeeps/gpsinput.o \
        jeeps/gpsmath.o jeeps/gpsmem.o  \
        jeeps/gpsproj.o jeeps/gpsprot.o jeeps/gpsread.o \
        jeeps/gpsrqst.o jeeps/gpssend.o jeeps/gpsserial.o jeeps/gpsutil.o
 
-OBJS=main.o queue.o route.o waypt.o util.o vecs.o mkshort.o \
-       coldsync/util.o coldsync/pdb.o $(GARMIN) $(JEEPS) $(FMTS)
+COLDSYNC=coldsync/util.o coldsync/pdb.o
+
+OBJS=main.o queue.o route.o waypt.o util.o vecs.o mkshort.o csv_util.o \
+       $(COLDSYNC) $(GARMIN) $(JEEPS) $(FMTS)
 
 all: gpsbabel
 
@@ -40,3 +42,7 @@ tiger.o: tiger.c defs.h queue.h magellan.h
 util.o: util.c defs.h queue.h
 vecs.o: vecs.c defs.h queue.h
 waypt.o: waypt.c defs.h queue.h
+psp.o: psp.c defs.h queue.h
+mxf.o: mxf.c csv_util.c defs.h queue.h csv_util.h
+ozi.o: ozi.c csv_util.c defs.h queue.h csv_util.h
+csv_util.o: csv_util.c csv_util.h defs.h 
index 7c502c5a1591b5a994ab9decbab49d1b9902cf2e..62cf1375d90b8425e54ce14dd71beb9d980e820b 100644 (file)
@@ -128,8 +128,11 @@ THE FORMATS
        complies with (at least) Maptech Terrain Navigator, Terrain
        Professional, Take a Hike, and ExpertGPS import/export MFX.
 
-  Maptech MXF
-       Maptech's MXF is a CSV on steroids.  Contributed by Alex Mottram.
+    OZI
+
+       OziExplorer Waypoint Format - Another CSV format file.  
+       Tested against OziExplorer v 3.90.3a / Shareware.
+       Contributed by Alex Mottram
 
 
 COMMON USAGE
index c2cd9c4f97ab38243b1da9193aa5c1209f118feb..a7ba546a88a124df1a161737c01591e2f58cfcd7 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "defs.h"
+#include "csv_util.h"
 #include <ctype.h>
 
 static FILE *file_in;
@@ -61,28 +62,62 @@ wr_deinit(void)
 static void
 data_read(void)
 {
-       char desc[80];
-       char *odesc = desc;
-       double lat,lon;
+       char buff[1024];
+       char *s;
+       int i;
        waypoint *wpt_tmp;
+       int linecount = 0;
 
-       while( fscanf(file_in, "%lf,%lf,%80[^\n]",
-                       &lat, &lon, desc) > 0) {
-               wpt_tmp = calloc(sizeof(*wpt_tmp),1);
-               if (wpt_tmp == NULL) {
+       do {
+               linecount++;
+               memset(&buff, '\0', sizeof(buff));
+               fgets(buff, sizeof(buff), file_in);
+
+               if (strlen(buff)) {
+
+                   wpt_tmp = calloc(sizeof(*wpt_tmp), 1);
+                   if (wpt_tmp == NULL) {
                        fatal(MYNAME ": cannot allocate memory\n");
+                   }
+
+                   s = buff;
+                   /* data delimited by commas, not enclosed */
+                   s = csv_lineparse(s, ",", "", linecount);
+
+                   i = 0;
+
+               while (s) {
+                       switch (i) {
+                       case 0:
+                               wpt_tmp->position.latitude.degrees = atof(s);
+                               break;
+                       case 1:
+                               wpt_tmp->position.longitude.degrees = atof(s);
+                               break;
+                       case 2:
+                               wpt_tmp->description = strdup(s);
+                               if (! wpt_tmp->description) 
+                                   fatal(MYNAME, ": cannot allocate memory\n");
+                               wpt_tmp->description = csv_stringtrim(wpt_tmp->description, " ");
+                               break;
+                       default:
+                               fprintf (stderr, "%s: Warning: unmapped data fields on line %d.\n", 
+                                       MYNAME, linecount);
+                               break;
+                       }
+                       i++;
+
+                       s = csv_lineparse(NULL, ",", "", linecount);
                }
-               while (*odesc == ' ' || *odesc == '\t') {
-                       odesc++;
-               }
-               wpt_tmp->shortname = strdup(odesc);
+           
                wpt_tmp->creation_time = time(NULL);
-
-               wpt_tmp->position.longitude.degrees = lon;
-               wpt_tmp->position.latitude.degrees = lat;
-
                waypt_add(wpt_tmp);
+
+       } else {
+               /* empty line */
        }
+
+    } while (!feof(file_in));
 }
 
 static void
@@ -92,6 +127,8 @@ gpsutil_disp(waypoint *wpt)
 
        lon = wpt->position.longitude.degrees;
        lat = wpt->position.latitude.degrees;
+        if (wpt->description) 
+           wpt->description = csv_stringclean(wpt->description, ",\"");
 
        fprintf(file_out, "%08.5f, %08.5f, %s\n",
                lat,
index aa13f1f1923381af55087acdb00118c4ce5721f2..47385f7580088754901a7488519e1967f31371f2 100644 (file)
@@ -29,6 +29,7 @@
  */
 
 #include "defs.h"
+#include "csv_util.h"
 #include <ctype.h>
 
 #define MYNAME "MXF"
 static FILE *file_in;
 static FILE *file_out;
 
-static char * 
-csvstringclean(char * string)
-{
-    static char * p1 = NULL;
-    char * p2 = NULL;
-    
-    if (! string) { 
-        return (string); /* :) */
-    }
-
-    p2 = string;
-    
-    while ((*p2) && (p2++)) { }
-    p2--;
-    
-    while (isspace(*p2)) {
-        *p2 = '\0';
-        p2--;
-    }
-    
-    p1 = string;
-    
-    while (isspace(*p1)) {
-        p1++;
-    }
-
-    /* yank quotes in pairs only if they are bounding us */
-    while ((*p1 == '"') && (*p2 == '"')) {
-        *p2 = '\0';
-        p2--;
-        p1++;
-    }
-
-    return (p1);    
-}
-
-/* string parser.  sorta like strtok with quotes & pointers..  */
-/* designed to handle quoted and delimited data within quotes. */
-static char * 
-csvparse(char *stringstart, char *delimiter)
-{
-    char *sp;
-    static char *p = NULL;
-    static char *tmp = NULL;
-    size_t dlen;
-    int quotedepth = 0;
-    short int dfound;
-
-    if (!p) {
-       p = stringstart;
-
-       if (!p) {
-           return (NULL);
-       }
-    }
-
-    if (tmp) {
-       free(tmp);
-       tmp = NULL;
-    }
-
-    sp = p;
-
-    dlen = strlen(delimiter);
-    dfound = 0;
-
-    while ((*p) && (! dfound)) {
-       if (*p == '"') {
-           if (quotedepth) 
-               quotedepth--;
-           else 
-               quotedepth++;
-       }
-
-       if ((!quotedepth) && (strncmp(p, delimiter, dlen) == 0)) {
-               dfound = 1;
-               
-       } else {
-               p++;
-       }
-
-    }
-
-    tmp = (char *) calloc((p - sp) + 1, sizeof(char));
-
-    if (! tmp) {
-       fatal(MYNAME ": cannot allocate memory\n");
-    }
-
-    strncpy(tmp, sp, (p - sp));
-
-    if (dfound) {
-        /* skip over the delimiter */
-        p += dlen;
-    } else {
-        /* end of the line */
-        p = NULL;
-    }
-
-    return (tmp);
-}
-
 static void 
 rd_init(const char *fname)
 {
@@ -171,7 +70,7 @@ wr_deinit(void)
 static void 
 data_read(void)
 {
-    char buff[256];
+    char buff[1024];
     char *s;
     waypoint *wpt_tmp;
     int i;
@@ -190,8 +89,9 @@ data_read(void)
                fatal(MYNAME ": cannot allocate memory\n");
            }
 
+           /* data delimited by commas, possibly enclosed in quotes.  */
            s = buff;
-           s = csvparse(s, ", ");
+           s = csv_lineparse(s, ",", "\"", linecount);
 
            i = 0;
            while (s) {
@@ -203,10 +103,18 @@ data_read(void)
                    wpt_tmp->position.longitude.degrees = atof(s);
                    break;
                case 2:
-                   wpt_tmp->description = strdup(csvstringclean(s));
+                   wpt_tmp->description = strdup(s);
+                   if (! wpt_tmp->description) 
+                       fatal(MYNAME, ": cannot allocate memory\n");
+
+                   wpt_tmp->description = csv_stringtrim(wpt_tmp->description, "");
                    break;
                case 3:
-                   wpt_tmp->shortname = strdup(csvstringclean(s));
+                   wpt_tmp->shortname = strdup(s);
+                   if (! wpt_tmp->shortname) 
+                       fatal(MYNAME, ": cannot allocate memory\n");
+
+                   csv_stringtrim(wpt_tmp->shortname, "");
                    break;
                case 4:
                     /* ignore.  another name-type  */
@@ -225,7 +133,7 @@ data_read(void)
                }
                i++;
 
-               s = csvparse(NULL, ", ");
+               s = csv_lineparse(NULL, ",", "\"", linecount);
            }
            
            if (i != 7) {
@@ -249,6 +157,9 @@ mxf_disp(waypoint * wpt)
     int icon = 47; /* default to "dot" */
     const char *color_hex = "ff0000";
 
+    csv_stringclean(wpt->shortname, ",\"");
+    csv_stringclean(wpt->description, ",\"");
+
     fprintf(file_out, "%08.5f, %08.5f, \"%s\", \"%s\", \"%s\", %s, %d\n",
            wpt->position.latitude.degrees, wpt->position.longitude.degrees,
            wpt->description, wpt->shortname, wpt->description, 
index 4699e18485731b5658edb5e01d2a8d417cd72759..0b2c73d993dad6493735bd31e98d50e71390d462 100755 (executable)
@@ -62,3 +62,7 @@ diff /tmp/ps.psp reference
 ${PNAME} -i geo -f geocaching.loc -o mxf -F /tmp/mxf.mxf
 diff /tmp/mxf.mxf reference
 
+# OZI (OziExplorer 1.1) file format
+${PNAME} -i geo -f geocaching.loc -o ozi -F /tmp/ozi.ozi
+diff /tmp/ozi.ozi reference
+
index 6dceb8837c72ee974be8efef27823e4f1e5a7071..d2adab48749013ddee9335b64c2a7480ab677fce 100644 (file)
@@ -44,6 +44,7 @@ extern ff_vecs_t psp_vecs;
 extern ff_vecs_t garmin_vecs;
 extern ff_vecs_t mxf_vecs;
 extern ff_vecs_t holux_vecs;
+extern ff_vecs_t ozi_vecs;
 
 static
 vecs_t vec_list[] = {
@@ -127,6 +128,11 @@ vecs_t vec_list[] = {
                "holux",
                "Holux (gm-100) .wpo Format"
        },
+       {
+               &ozi_vecs,
+               "ozi",
+               "OziExplorer Waypoint"
+       },
 
         {
                NULL,